package com.imooc.luckymoney.util;

import com.imooc.luckymoney.entity.Luckymoney;
import com.imooc.luckymoney.entity.Result;
import com.imooc.luckymoney.enums.ResultEnum;
import com.imooc.luckymoney.exception.LuckymoneyException;
import com.imooc.luckymoney.exception.LuckymoneyFormException;

public class ResultUtil {

    public static Result success(Luckymoney luckymoney){
        Result result = new Result<Luckymoney>();
        result.setCode(0);
        result.setMsg("成功");
        result.setData(luckymoney);
        return result;
    }

    public static Result error(LuckymoneyException luckymoneyException){
        Result result = new Result();
        result.setCode(luckymoneyException.getCode());
        result.setMsg(luckymoneyException.getMessage());
        return result;
    }

    public static Result<String> formError(LuckymoneyFormException luckymoneyFormException){
        Result<String> result = new Result<>();
        result.setCode(luckymoneyFormException.getCode());
        result.setMsg(luckymoneyFormException.getMessage());
        result.setData(luckymoneyFormException.getFormMsg());
        return result;
    }
}
